<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="80px">
          <el-row>
            <el-col :span="6">
              <el-form-item label="区域" prop="districtId">
                <el-select
                  v-model="queryParams.districtId"
                  placeholder="请选择"
                  clearable
                  filterable
                  @change="handleQuery"
                >
                  <el-option
                    v-for="item in AreaData"
                    :key="item.districtId"
                    :label="item.districtName"
                    :value="item.districtId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="门店" prop="storeId">
                <el-select
                  v-model="queryParams.storeId"
                  placeholder="请选择"
                  filterable
                  clearable
                >
                  <el-option
                    v-for="(item, index) in $store.state.user.stores"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="时间" prop="date">
                <el-date-picker
                  v-model="queryParams.date"
                  type="daterange"
                  align="right"
                  unlink-panels
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :picker-options="pickerOptions"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>

    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">城市经理周报</div>
        <div class="op_right"></div>
      </div>

      <div class="table_list">
        <el-table
          :data="CityManagerWeekList"
          stripe
          style="width: 100%"
          v-loading="loading"
          @sort-change="handleSort"
        >
          <el-table-column
            prop="districtName"
            label="区域"
            align="center"
            width="200"
          >
          </el-table-column>
          <el-table-column prop="storeName" label="门店名称" width="160px">
          </el-table-column>
          <el-table-column prop="userName" label="店长名称" width="160px">
          </el-table-column>
          <el-table-column prop="manualDay" label="日期时间段" width="200px">
          </el-table-column>
          <el-table-column
            prop="taskTurnover"
            label="本月业绩任务"
            width="150px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="relayMoney"
            label="本周实际业绩"
            width="150px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="taskTurnoverWeek"
            label="本周应完成业绩"
            width="150px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="reduceMoney"
            label="完成业绩差额"
            width="130px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="taskCustomerCount"
            label="本月总客量任务"
            width="150px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="customerCountWeek"
            label="本周实际客量"
            width="130px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="taskCustomerCountWeek"
            label="本周应完成客量"
            width="150px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="reduceCustomerCount"
            label="本周客量差额"
            width="130px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="relayMoneyAverage"
            label="本周业绩日均"
            width="130px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="relayMoneyAverageBefore"
            label="上周周业绩日均"
            width="150px"
            sortable="custom"
          >
          </el-table-column>

          <el-table-column
            prop="cardRechargeWeek"
            label="本周充卡数"
            width="130px"
            sortable="custom"
          >
          </el-table-column>

          <el-table-column
            prop="cardMoneyWeek"
            label="本周充卡金额"
            width="130px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="cardRechargePercentage"
            label="充卡率"
            sortable="custom"
            width="90px"
          >
          </el-table-column>
          <el-table-column
            prop="cardRechargeOne"
            label="充卡客单价"
            width="130px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column prop="clockCountAdd" label="加钟" sortable="custom">
          </el-table-column>
          <el-table-column
            prop="clockCountAddPercentage"
            label="加钟率"
            sortable="custom"
            width="90px"
          >
          </el-table-column>
          <el-table-column
            prop="customerVisitor"
            label="约客数"
            width="100px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="moneyHospitality"
            label="待客提成金额"
            width="130px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column
            prop="moneyItemHospitality"
            label="待客项目总金额"
            width="150px"
            sortable="custom"
          >
          </el-table-column>
          <el-table-column prop="storeRecharge" label="充卡" sortable="custom">
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { getCityManagerWeek } from "@/api/business/task";
import timer from "@/components/getTime/timer";
import { getManagerDistrict } from "@/api/bpm/commission";

import { getMonday } from "@/utils/utils";

export default {
  name: "Storeadmincitymanagerweek",
  components: { timer },
  data() {
    return {
      CityManagerWeekList: [], // 城市经理 周报
      loading: false,

      value: "",
      // 查询参数
      queryParams: {
        storeId: "",
        date: [],
        districtId: "",
        field: "",
        sortType: "",
      },
      total: 0,
      AreaData: [], // 区域数据

      pickerOptions: {
        shortcuts: [
          {
            text: "本周",
            onClick(picker) {
              const start = new Date();
              const end = new Date();
              const nows = start.getDay() || 7; // 注意周日算第一天，如果周日查询本周的话，天数是0，所有如     果是0，默认设置为7
              start.setTime(start.getTime() - 3600 * 1000 * 24 * (nows - 1));
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "上周",
            onClick(picker) {
              const dataValue = new Date();
              const year = dataValue.getFullYear();
              const month = dataValue.getMonth() + 1;
              const day = dataValue.getDate();
              var thisWeekStart; // 本周周一的时间
              if (dataValue.getDay() === 0) {
                // 周天的情况；
                thisWeekStart =
                  new Date(year + "/" + month + "/" + day).getTime() -
                  (dataValue.getDay() + 6) * 86400000;
              } else {
                thisWeekStart =
                  new Date(year + "/" + month + "/" + day).getTime() -
                  (dataValue.getDay() - 1) * 86400000;
              }
              const prevWeekStart = thisWeekStart - 7 * 86400000; // 上周周一的时间
              const prevWeekEnd = thisWeekStart - 1 * 86400000; // 上周周日的时间
              const start = new Date(prevWeekStart); // 开始时间
              const end = new Date(prevWeekEnd); // 结束时间
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },

  mounted() {},

  created() {
    this.initDate();
    this.getList();
    this.getAreaData();
  },

  methods: {
    initDate() {
      const date = getMonday();

      this.queryParams.date = [date.s, date.e];
      console.log("date.", date);
    },
    handleSort({ column, prop, order }) {
      if (column.order === "ascending") {
        this.queryParams.sortType = "ASC";
      } else if (column.order === "descending") {
        this.queryParams.sortType = "DESC";
      }
      this.queryParams.field = column.property;
      this.getList();
    },
    // 获取区域数据
    getAreaData() {
      getManagerDistrict(this.queryParams)
        .then((res) => {
          const { code, data } = res;
          if (code === 0) {
            this.AreaData = data;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      this.initDate();
      this.handleQuery();
    },

    // 表单重置
    resetFormData(formName) {
      console.log(this.$refs[formName]);
      this.$refs[formName].resetFields();
    },

    // 城市经理周报
    getList() {
      this.loading = true;
      let queryParams = JSON.parse(JSON.stringify(this.queryParams));

      if (!!this.queryParams.date) {
        queryParams.startDate = this.queryParams.date[0];
        queryParams.endDate = this.queryParams.date[1];
        queryParams.date = [];
      }
      delete queryParams.date;

      getCityManagerWeek(queryParams)
        .then((res) => {
          // console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.CityManagerWeekList = data;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.goodTop {
  width: 100%;
  height: 48px;
  background: #ffffff;
  display: flex;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.6);
  line-height: 48px;
  padding-left: 16px;
  .good_list {
    margin-right: 32px;
  }

  .good_active {
    color: #0052d9;
    border-bottom: 1px solid #0052d9;
  }
}

.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.Order_box {
  display: flex;
  margin-left: -50px;
  .select_ipt {
    width: 130px;
    margin-right: 10px;
  }
}

.pay_ipt {
  margin-left: 50px;
}

.order_ipt {
  margin-left: -120px;
}
</style>
